//显示静止小球
//下落
//上下
//斜
//控制速度
//尝试边框
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
//小球坐标(x, y); 边框宽度和高度 

void PrintAll(int x, int y, int width, int height) { 
    int k,i,j;
    for ( k = 0; k < width; k++) printf("█"); //障碍可以用H 
    printf("\n");
	for ( i = 1; i < height - 1; i++) {  
    	printf("█");
    	for ( j = 1; j < width - 1; j++) {
    		if (i == y && j == x) printf("Ο"); //希腊字母Omicron 
			else printf("  ");	
		}
		printf("█\n"); 
	}
	for ( k = 0; k < width; k++) printf("█");
	printf("\n\n");
}

int main() {
	int x, y, velocity_x, velocity_y;
	x = 1, y = 1;
	velocity_x = velocity_y = 1;
	
	int left, down, top, right;
	left = top = 0, down = 20, right = 40;
	
	while (1) {	
		PrintAll(x, y, right, down); 
		y += velocity_y; 
		x += velocity_x;
		if (y + 2 == down || y - 1 == top) { //碰到障碍
		   velocity_y = -velocity_y;
		   printf("\a"); 
        } 
		if (x + 2 == right || x - 1 == left) { //碰到障碍
		   velocity_x = -velocity_x;
		   printf("\a");	
        }  
        
		Sleep(50);
		system("cls");
	}	
	return 0;
}
